home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 134 / pascal / malloc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-04-17  |  1.4 KB  |  52 lines

  1. {
  2.         Malloc.pas - program to show all memory segments and their addresses.
  3.         03/09/87 MJC
  4.         Copyright 1987 OSS
  5.         Run this program at different times to see what is happening to
  6.         free memory.
  7.  
  8.         compile for TOS
  9. }
  10. { DON'T tamper with this next line! }
  11. {$S1}   { set startup routines to use only 1k of system mem for stack }
  12.  
  13. Program Malloc;
  14.  
  15. Const
  16.  
  17.    BlockSize = $ffffffff;       { ffffffff hex is -1 Long }
  18.  
  19. Var
  20.  
  21.    Address : Long_Integer;    { address of mem block }
  22.    Size : Long_Integer; { size of mem block }
  23.    NoMore : Long_Integer;
  24.    TTL : Long_Integer;
  25.  
  26. Function Malloc( Size : Long_Integer ) : Long_Integer;
  27.    Gemdos( $48 );
  28.  
  29.    Begin
  30.       NoMore := 0;
  31.       TTL := 0;
  32.       writeln( 'Free Memory Segments -- Copyright 1987 OSS.' );
  33.       writeln;
  34.       writeln( 'Address     Length' );
  35.       writeln( '--------   --------' );
  36.       Repeat
  37.          Size := Malloc( BlockSize );   { find largest block size }
  38.          IF ( Size <> NoMore ) THEN Begin
  39.             TTL := TTL + Size;
  40.             Address := Malloc( Size );     { get address of base }
  41.             writeln( Address:8:h,'   ', Size:8:h )
  42.             end;
  43.       Until ( Size = NoMore );
  44.    writeln;
  45.    writeln( 'Total Free Mem = ', TTL:8:h, ' or ', TTL, ' decimal.' );
  46.    writeln;
  47.    write( 'Press [RETURN] ' );
  48.    readln;
  49.    End.
  50.  
  51. {EOF:MALLOC.PAS}
  52.